import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { MemberForm, MemberPage, MemberQuery } from "./types";

/**
 * 获取用户分页列表
 *
 * @param queryParams
 */
export function getMemberPage(
  queryParams: MemberQuery
): AxiosPromise<PageResult<MemberPage[]>> {
  return request({
    url: "/admin/member/index",
    method: "get",
    params: queryParams,
  });
}

/**
 * 获取用户表单详情
 *
 * @param ids
 */
export function getMemberForm(ids: number): AxiosPromise<MemberForm> {
  return request({
    url: "/admin/member/edit",
    method: "get",
    params: {
      ids: ids,
    },
  });
}

/**
 * 添加用户
 *
 * @param data
 */
export function addMember(data: any) {
  return request({
    url: "/admin/member/add",
    method: "post",
    data: data,
  });
}

/**
 * 修改用户
 *
 * @param id
 * @param data
 */
export function updateMember(data: MemberForm) {
  return request({
    url: "/admin/member/edit",
    method: "put",
    data: data,
  });
}

/**
 * 修改用户密码
 *
 * @param id
 * @param password
 */
export function updateMemberPassword(id: number, password: string) {
  return request({
    url: "/admin/member/resetPassword",
    method: "patch",
    params: { password: password },
  });
}

/**
 * 删除用户
 *
 * @param data
 */
export function deleteMembers(data: any) {
  return request({
    url: "/admin/member/del",
    method: "delete",
    data,
  });
}

